#include "GameUtilities.h"

void drawGrid(BeanieCore* a_core, float a_width, float a_height, int a_color)
{
	if(a_core == 0) return;

	float itrW = 0.0f;
	float itrH = 0.0f;

	while(itrW <= a_core->getWindowWidth())
	{
		itrW += a_width;
		V2DF s(itrW,0.0f);
		V2DF e(itrW,(float)a_core->getWindowHeight());
		a_core->drawLine(s,e,a_color);
	}

	while(itrH <= a_core->getWindowHeight())
	{
		itrH += a_height;
		V2DF s(0.0f,itrH);
		V2DF e((float)a_core->getWindowWidth(),itrH);
		a_core->drawLine(s,e,a_color);
	}
}

void drawRect(BeanieCore* a_core, V2DF* a_verts, int a_color)
{
	if(a_core == 0 || a_verts == 0) return;

	a_core->drawLine(a_verts[0],a_verts[1],a_color);
	a_core->drawLine(a_verts[1],a_verts[2],a_color);
	a_core->drawLine(a_verts[2],a_verts[3],a_color);
	a_core->drawLine(a_verts[3],a_verts[0],a_color);
}

void drawRect(BeanieCore* a_core, V2DF a_pos, V2DF a_dir,
	V2DF* a_verts, int a_color)
{
	if(a_core == 0 || a_verts == 0) return;

	a_core->drawLine(a_pos,a_pos+a_dir,a_color);
	drawRect(a_core,a_verts,a_color);
}

void drawCircle(BeanieCore* a_core, V2DF a_pos,
	float a_rad, int a_seg, int a_color)
{
	if(a_core == 0) return;
	
	List<V2DF> cir;
	float angle = (float)((2.0f*MATH_PI)/a_seg);
	for(int i = 0; i < a_seg; i++)
	{
		float theta = i*angle;
		float x = (float)(a_pos.x + a_rad * cos(theta));
		float y = (float)(a_pos.y - a_rad * sin(theta));
		cir.insertBack(V2DF(x,y));
	}

	int last = cir.size()-1;
	for(int i = 0; i < cir.size(); i++)
	{
		if(i != last)
			a_core->drawLine(cir[i],cir[i+1],a_color);
		else
			a_core->drawLine(cir[i],cir[0],a_color);
	}
}

void drawCircle(BeanieCore* a_core, V2DF a_pos,
	V2DF a_dir, float a_rad, int a_seg, int a_color)
{
	if(a_core == 0) return;
	
	a_core->drawLine(a_pos,a_pos+a_dir,a_color);
	drawCircle(a_core,a_pos,a_rad,a_seg,a_color);
}

void drawTri(BeanieCore* a_core, V2DF* a_verts, int a_color)
{
	if(a_core == 0 || a_verts == 0) return;

	a_core->drawLine(a_verts[0],a_verts[1],a_color);
	//a_core->drawLine(a_verts[1],a_verts[2],a_color);
	a_core->drawLine(a_verts[2],a_verts[0],a_color);
}